package com.gitee.cui.netty.decoder;

import com.gitee.cui.util.Logger;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * 字节转整型解码器，不需要进行ByteBuf的长度判断，由Netty进行判断，并决定是否可以正常解码
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/22 17:26
 **/
public class Byte2IntegerReplayDecoder extends ReplayingDecoder<Integer> {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        int i = in.readInt();
        Logger.info("通过ReplayingDecoder解码出一个整数：" + i);
        out.add(i);
    }
}
